window.WpsUtils = (function () {
  return {
    type: WpsClientTypeEnum.文档,

    /**
     * @returns {Wps.WpsDocument}
     */
    getActiveDto() {
      return wps.ActiveDocument;
    },

    /**
     * @returns {Wps.WpsDocuments}
     */
    getWorkDtos() {
      return wps.WpsApplication().Documents;
    },

    /**
     * 获取当前文档内容
     */
    getDocContent() {
      return this.getActiveDto().Content.Text;
    },

    /**
     * 获取当前文档内容（仅文本）
     */
    getDocContentText() {
      return JSON.parse(JSON.stringify(this.getDocContent()).replace(/\\u[0-9A-Fa-f]{4}/g, ''));
    },

    /**
     * 查找文本范围对象
     */
    findTextRanges(text) {
      const cntRange = this.getActiveDto().Content;
      cntRange.Find.ClearFormatting();// 清除查找
      cntRange.Find.Text = text;
      const result = [];
      while (cntRange.Find.Execute()) {
        result.push(this.getActiveDto().Range(cntRange.Start, cntRange.End));
      }
      return result;
    },
  };
})();